<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>电子发票管理系统—找回密码</title>
<link rel="stylesheet" href="webjars/bootstrap/3.3.7-1/css/bootstrap.css" />
<script src="static/jquery-easyui-1.5.5.3/jquery.min.js"></script>
<script type="text/javascript">
	$(function(){
		var a = window.innerHeight - 100 + "px";
		$("#logo").css('height', a);
	});
	$(window).resize(function(){
	    var a = window.innerHeight - 100 + "px";
		$("#logo").css('height', a);
	});
	function CheckMail(mail) {
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (filter.test(mail)) 
			return true;
		else {
			return false;
		}
	}
	function fun(str){
		$.post('username', {username: str}, function(data){
			if(!data){
				$("#yzm").prop('disabled', true);
				$("#username-error").html("电子邮箱输入错误！");
			}else{
				if(CheckMail(str)){
					$("#username-error").html("");
					$("#yzm").prop('disabled', false);					
				}else{
					$("#yzm").prop('disabled', true);
					$("#username-error").html("请输入正确的邮箱格式！");
				}
			}
		});
	}
	function fun_1(str){
		$("#code-error").html("");
		$.post('yz', {code: str}, function(data){
			if(!data){
				$("#code-error").html("验证码输入错误！");
			}else{
				$("#code-error").html("");
			}
		});
	}
	function fun1(){
		$("#pwd1-error").html("");
	}
	function fun2(){
		$("#pwd2-error").html("");
	}
	var i = 60;
	var dsq1;
	function sj(){
		$("#yzm").val("("+i+")获取验证码");
		$("#yzm").prop('disabled', true);
		i--;
		if(i == 0){
			i = 60;
			window.clearInterval(dsq1);
			$("#yzm").val("重新获取验证码");
			$("#yzm").prop('disabled', false);
		}
	}
	$(function(){
		$("#pwd1-error").html("");
		$("#pwd2-error").html("");
		$("#yzm").click(function(){
			var username = $("#username").val();
			dsq1 = setInterval("sj();", 1000);
			$.post('yx', {username: username}, function(data){
			});
		});
		$("#btn_1").click(function(){
			var username = $("#username").val();
			var pwd1 = $("#pwd1").val();
			var pwd2 = $("#pwd2").val();
			var code = $("#code").val();
			if(username == "" || username == null){
				$("#username-error").html("请输入电子邮箱");
			}else if(pwd1 == "" || pwd1 == null){
				$("#pwd1-error").html("请输入新密码");
			}else if(pwd2 == "" || pwd2 == null){
				$("#pwd2-error").html("请再次输入新密码");
			}else if(pwd1 != pwd2){
				$("#pwd2-error").html("两次密码不一致");
			}else if(code == "" || code == null){
				$("#code-error").html("请输入验证码");
			}else{
				$.post('yz', {code: code}, function(data){
					if(data){
						$.post("zhmm1", {"username": username, "password": pwd1}, function(data){
							alert(data);
							window.location.href="login1";
						});
					}else{
						$("#code-error").html("验证码输入错误！");
					}
				});
			}
		});
	});
</script>
<style type="text/css">
	#logo{
		background: url(static/img/denglu.jpg) no-repeat;
		background-size: cover;	
	}
	#denlu{
		width: 32%;
		background: #000000;
		position:absolute;
		margin-top: 6%;
		margin-left: 62%;
		border-radius: 8px;
		opacity: 0.7;
	}
	#denlu form{
		color: #DDDDDD;
	}
	h1{
		font-family: "楷体";
		margin-top: 18px;
		color: red;
		margin-left: 50px;
	}
	.error{
		color: red;
	}
</style>
</head>
<body>
	<div style="height: 100px;">
		<img src="static/img/logo.png" height="100px" style="margin-left: 80px;"/>
		<a href="login1" style="float: right; line-height: 100px; margin-right: 80px;"><span class="glyphicon glyphicon-user"></span>  登录</a>
		<a href="login" style="float: right; line-height: 100px; margin-right: 20px;"><span class="glyphicon glyphicon-home"></span>  首页</a>
	</div>
	<div id="logo">
		<div id="denlu">
			<form action="save" id="myform" method="post" class="form-horizontal" >
				<h1>找回密码<span style="font-size: 18px;">（此功能只针对租户管理员）</span></h1><center><hr style="width: 90%;" /></center>
				<div class="form-group">
					<label for="user" class="col-md-3 control-label" >电子邮箱</label>
					<div class="col-md-7">
						<input type="text" class="form-control" name="username" id = "username" onchange="fun(this.value);" placeholder="登录邮箱">
					</div>
					<div><label id="username-error" class="error col-lg-offset-4" for="username"></label></div>
				</div>
				<div class="form-group">
					<label for="pass" class="col-md-3 control-label">请输入新密码</label>
					<div class="col-md-7">
						<input type="password" class="form-control" onchange="fun1();" name="pwd1" id = "pwd1" placeholder="请输入新密码">
					</div>
					<div><label id="pwd1-error" class="error col-lg-offset-4" for="pwd1"></label></div>
				</div>
				<div class="form-group">
					<label for="pass" class="col-md-3 control-label">请确认新密码</label>
					<div class="col-md-7">
						<input type="password" class="form-control" onchange="fun2();" name="pwd2" id = "pwd2" placeholder="请确认新密码">
					</div>
					<div><label id="pwd2-error" class="error col-lg-offset-4" for="pwd2"></label></div>
				</div>
				<div class="form-group">
					<label for="pass" class="col-md-3 control-label">验证码</label>
					<div class="col-md-4">
						<input type="text" onchange="fun_1(this.value);" class="form-control" name="code" id = "code" placeholder="验证码">
					</div>
					<div class="col-md-3">
						<label class="control-label" style="padding-top: 0px;"><input disabled="disabled" type = "button" id="yzm" class="btn btn-success" value="发送验证码" /></label>
					</div>
					<div><label id="code-error" class="error col-lg-offset-4" for="code"></label></div>
				</div>
				<div class="form-group">
					<div class="col-md-7 col-md-offset-2">
						<button type="button" id = "btn_1" style="width:100%;" class="btn btn-success">确定</button>
					</div>
				</div><br>					
			</form>
		</div>
	</div>
</body>
</html>